<?php
namespace Common\helpers;
include 'sms_sdk/aliyun-php-sdk-core/Config.php';
include_once 'sms_sdk/Dysmsapi/Request/V20170525/SendSmsRequest.php';
include_once 'sms_sdk/Dysmsapi/Request/V20170525/QuerySendDetailsRequest.php';
use DefaultAcsClient;
use DefaultProfile;
use Dysmsapi\Request\V20170525\SendSmsRequest;
class Sms{
    public static function sendSms($number,$temp_id,$jsonStr=null){
        //此处需要替换成自己的AK信息
        $accessKeyId =C('accessKeyId');
        $accessKeySecret = C('accessKeySecret');
        //短信API产品名
        $product = "Dysmsapi";
        //短信API产品域名
        $domain = "dysmsapi.aliyuncs.com";
        //暂时不支持多Region
        $region = "cn-hangzhou";
        //初始化访问的acsCleint
		
        $profile = DefaultProfile::getProfile($region, $accessKeyId, $accessKeySecret);
		
        DefaultProfile::addEndpoint("cn-hangzhou", "cn-hangzhou", $product, $domain);
        $acsClient= new DefaultAcsClient($profile);
		
        $request = new SendSmsRequest;
		
        //必填-短信接收号码
        $request->setPhoneNumbers($number);
        //必填-短信签名
        $request->setSignName(C('signName'));
        //必填-短信模板Code
        $request->setTemplateCode($temp_id);
        //选填-假如模板中存在变量需要替换则为必填(JSON格式)
        if(isset($jsonStr)){
            $request->setTemplateParam($jsonStr);
        }
        //发起访问请求
        return $acsClient->getAcsResponse($request);
    }
}
